package com.example.algorithm.CQueue;

import java.util.PriorityQueue;

/**
 * @author: dangwen
 * @createDate: 2021/6/15
 * 703.返回数据流中第K大元素
 */
public class KthLargest {

    PriorityQueue<Integer> pq;
    Integer k;

    public KthLargest(int k, int[] nums) {
        this.k = k;
        pq = new PriorityQueue<>();
        for (int i : nums){
            add(i);
        }
    }

    public int add(int val) {
        pq.offer(val);
        if(pq.size() > k){
            pq.poll();
        }
        return pq.peek();
    }

}
